
<template>
  <!-- 项目计划查询弹窗 -->
  <div>
    <!-- 搜索 -->
    <TopFilter :list="topFilterInit" :cols="3" labelWidth="100" @filterChange="changeHandle"></TopFilter>
    <!-- table -->
    <FilterTable
      ref="table"
      :columns="columns"
      :isSelectColumn="isSelectColumn"
      :fetchapi="fetchApi"
      :params="fetchParams"
      :datakey="'records'"
      selectionType="single"
      :height="'auto'"
      :onRowSelectChange="onRowSelectChange1"
      :onColumnsChange="columns => this.columns = columns"
      columnsRef="projectOperating_case_departmentReport_projectPlanMadal_01"
    ></FilterTable>

    <div
      :style="{
        position: 'absolute',
        left: 0,
        bottom: 0,
        right: 0,
        zIndex: 9,
        borderTop: '1px solid #e9e9e9',
        padding: '10px 20px',
        background: '#fff',
        textAlign: 'right'
      }"
    >
      <el-button @click="goback">取 消</el-button>
      <el-button type="primary" :loading="reqOKLoading" @click="reqOK">确 认</el-button>
    </div>
  </div>
</template>

<script>
import { getProjectPlan } from '@/api/cms-api/projectOperating/case/oemCollect/index';
import { selectListByBill } from '@/api/cms-api/projectOperating/plan/index';
import { dictionary } from '@/utils/dictMixin';
import { formatdateByDay } from '@/utils/index';
export default {
  mixins: [dictionary],
  props: {
    fatherReq: Function,
    fatherGoBack: Function,
    initDate: {
      type: Object,
      required: false
    }
  },
  //初始化数据  全局变量
  data() {
    return {
      topFilterInit: this.topFilterInitFun(),
      columns: this.creatHeader(),
      isSelectColumn: true,
      fetchApi: getProjectPlan, //ipa 接口
      fetchParams: { planStatus: 25311009, planStartDateBegin: this.initDate.initDateStart, planStartDateEnd: this.initDate.initDateEnd }, //参数
      choose: [], //选中的对象
      reqOKLoading: false
    };
  },
  //方法、事件
  methods: {
    //选中数据
    async onRowSelectChange1(val) {
      this.choose = val[0];
      //选中一条数据查询是否有对应附件
      if (val[0] != null) {
        let fileParams = { planId: val[0].planId, billType: 25781001 };
        await selectListByBill(fileParams).then(res => {
          if (res.data.length > 0) {
            let caseUrlList = [];
            for (let j = 0; j < res.data.length; j++) {
              let o1 = { name: res.data[j].fileName };
              let o2 = { url: res.data[j].fileId };
              let a = Object.assign(o1, o2);
              caseUrlList.push(a);
            }
            // debugger;
            val[0] = Object.assign({}, { projectFile: caseUrlList }, val[0]);
          }
          this.choose = val[0];
        });
      }
    },
    //确认
    reqOK() {
      if (this.choose == null) {
        this.$notify.warning({ title: '提示信息', message: '请选择一个项目!' });
        return;
      }
      this.reqOKLoading = true;
      this.fatherReq(this.choose);
    },
    //取消
    goback() {
      this.fatherGoBack();
    },
    //搜索数据
    topFilterInitFun() {
      return [
        { type: 'INPUT', label: '项目编号', fieldName: 'planCode', initialValue: '' },
        { type: 'INPUT', label: '项目名称', fieldName: 'projectName', initialValue: '' },
        {
          type: 'RANGE_DATE',
          label: '项目开始时间',
          fieldName: 'planStartDate',
          initialValue: ''
        }
      ];
    },
    //table表头和数据源
    creatHeader() {
      return [
        {
          title: '序号',
          dataIndex: 'index',
          width: 80,
          sorter: true,
          render: props => {
            return <span>{props.row.index + 1}</span>;
          }
        },
        {
          title: '项目编号',
          dataIndex: 'planCode',
          sorter: true
        },
        { title: '项目名称', dataIndex: 'projectName', sorter: true },
        { title: '事业部', dataIndex: 'orgId', sorter: true, hidden: true },
        { title: '事业部', dataIndex: 'orgName', sorter: true },
        {
          title: '审核状态',
          dataIndex: 'planStatus',
          sorter: true,
          filterItems: this.createDictList('2531'),
          render: props => {
            //编码转汉字
            return <span>{this.createDictText(props.row.planStatus, '2531')}</span>;
          }
        },
        {
          title: '项目开始时间',
          dataIndex: 'planStartDate',
          sorter: true,
          render: props => {
            return <span>{formatdateByDay(props.row.planStartDate)} </span>;
          }
        }
      ];
    },
    //搜索回调
    changeHandle(data) {
      if (!data) {
        data = { planStartDate: [] };
      }
      this.fetchParams = Object.assign(
        {
          planStartDateBegin: data.planStartDate[0] || undefined,
          planStartDateEnd: data.planStartDate[1] || undefined,
          planStatus: 25311009
        },
        data
      );
      // this.fetchParams = data;
      // this.fetchParams = Object.assign({}, { planStatus: 25311009 }, this.fetchParams);
    }
  }
};
</script>

<style scoped>
</style>
